package com.ibiaoke.boss.controller;

import com.ibiaoke.common.base.BaseController;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.response.Res;
import com.ibiaoke.system.entity.TopicPage;
import com.ibiaoke.system.entity.vo.TopicPageVO;
import com.ibiaoke.system.service.TopicPageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class BossTopicPageController extends BaseController {

    @Autowired
    private TopicPageService topicPageService;

    /**
     *保存专题活动页
     * @param topicPageVO
     * @param bindingResult
     * @return
     */
    @RequestMapping("/saveTopicPage")
    @ResponseBody
    public Res saveTopicPage(@Validated TopicPageVO topicPageVO, BindingResult bindingResult) {
        handleValidate(bindingResult);
        topicPageService.saveTopicPage(topicPageVO);
        return Res.create();
    }

    /**
     * 修改专题活动页
     * @param topicPageVO
     * @return
     */
    @RequestMapping("/updateTopicPage")
    @ResponseBody
    public Res updateTopicPage(TopicPageVO topicPageVO) {
        topicPageService.updateTopicPage(topicPageVO);
        return Res.create();
    }

    /**
     * 查询专题活动页列表
     * @param position
     * @param page
     * @return
     */
    @RequestMapping("/listTopicPage")
    @ResponseBody
    public Res listTopicPage(Integer position,Integer showStatus, Page page) {
        List<TopicPage> list = topicPageService.listTopicPage(position,showStatus,page);
        return Res.create().addResponse("TopicPageList", list).addResponse("page", page);
    }


    /**
     * 获取专题活动页详情
     * @param topicPageId
     * @return
     */
    @RequestMapping("/getTopicPage")
    @ResponseBody
    public Res getTopicPage(Integer topicPageId) {
        TopicPage topicPage = topicPageService.getTopicPage(topicPageId);
        return Res.create().addResponse("topicPage", topicPage);
    }

    /**
     * 删除专题活动页
     * @param topicPageId
     * @return
     */
    @RequestMapping("/deleteTopicPage")
    @ResponseBody
    public Res deleteTopicPage(Integer topicPageId) {
        topicPageService.deleteTopicPage(topicPageId);
        return Res.create();
    }
}
